﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreProject.IRepository;
using CoreProject.IService;
using CoreProject.Model;
namespace CoreProject.Service
{
    public class AuthorityService : BaseService<Authority>, IAuthorityService
    {
        private readonly IAuthorityRepository _repository;

        public AuthorityService(IAuthorityRepository repository) : base(repository)
        {
            this._repository = repository;
        }

        public async Task<bool> AddAuth(int rid, int[] ids)
        {
            List<Authority> list = new List<Authority>();
            foreach (int aid in ids)
            {
                Authority auth = new Authority()
                {
                    AuthId = 0,
                    RoleId=rid,
                    MenuId = aid,
                    Sort = 0,
                    LastTime = DateTime.Now
                };
                list.Add(auth);
            }

            return await _repository.AddAuth(rid,list);
        }

        public async Task<List<Authority>> GetAuthListByRid(int rid)
        {
           return await _repository.GetAuthListByRid(rid);
        }
    }
}
